package com.example.doer.reading;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ab.fragment.AbFragment;

import java.util.ArrayList;
import java.util.List;


public class FragmentOne extends AbFragment {
    private TabLayout tabLayout;
    private TabLayout.Tab one;
    private TabLayout.Tab two;
    private FragmentManager fragmentManager;

    public FragmentOne(FragmentManager f) {
        this.fragmentManager=f;
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_one,container,false);

        Fragment booklist_frag=new BookListFragment();
        Fragment bookstore_frag=new BookStoreFragment();
        List<Fragment> list=new ArrayList<Fragment>();
        list.add(booklist_frag);
        list.add(bookstore_frag);

        ViewPager viewPager=(ViewPager)view.findViewById(R.id.viewpager);
        MyFragmentAdapter myFragmentAdapter=new MyFragmentAdapter(list,fragmentManager);
        viewPager.setAdapter(myFragmentAdapter);

        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout);
        tabLayout.setupWithViewPager(viewPager);
        one=tabLayout.getTabAt(0);
        two=tabLayout.getTabAt(1);
        one.setText("书架");
        two.setText("书城");

        return view;
    }



}
